package Common.Filters;

import java.util.*;
import java.io.*;

public class StopWordsFilter implements IFilter
{
	private Hashtable stopwordList = null;
	
	public boolean isStopWord(String word)
	{
		if(this.stopwordList == null)
		{
			stopwordList = new Hashtable();
			BufferedReader input = null;
			try 
			{
				input = new BufferedReader(new FileReader("StopWords.txt"));
				String line = null;
				while (( line = input.readLine()) != null)
					stopwordList.put(line, line);
			}
			catch (FileNotFoundException ex) 
			{
				ex.printStackTrace();
			}
			catch (IOException ex)
			{
				ex.printStackTrace();
			}
			finally 
			{
				try 
				{
					if (input!= null) 
						input.close();
				}
				catch (IOException ex) 
				{
					ex.printStackTrace();
				}
			}
		}
		return  stopwordList.containsKey(word);
	}
	
	public String ApplyFilter(String word)
	{
		if(isStopWord(word)) {
			word = null;
		}
		return word;
	}
}
